﻿// Study0808.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第八章 多态 实验

#include <iostream>
using namespace std;

class Vehicle
{
public:
	virtual void run() = 0;
	virtual void stop() = 0;
	virtual ~Vehicle();
};
Vehicle::~Vehicle()
{
	cout << "vehicle destoried" << endl;
}


class Bicycle :public Vehicle
{
public:
	void run() override;
	void stop() override;
	~Bicycle() override;
};

void Bicycle::run()
{
	cout << "bicycle is running" << endl;
}
void Bicycle::stop()
{
	cout << "bicycle has stop" << endl;
}

Bicycle::~Bicycle()
{
	cout << "bicycle destoried" << endl;
}

class Car :public Vehicle
{
public:
	void run() override;
	void stop() override;
	~Car() override;
};
void Car::run()
{
	cout << "car is running" << endl;
}
void Car::stop()
{
	cout << "car has stop" << endl;
}
void func(Vehicle* v)
{
	v->run();
	v->stop();
}
Car::~Car()
{
	cout << "car destoried" << endl;
}
int main()
{
	Bicycle by;
	Car car;
	func(&by);
	func(&car);

	return 0;
}


